package tests;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import entity.general.MinTime;

public class TimeTest {

	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testSimpleTime() {
		MinTime t = new MinTime(10, 10);
		assertEquals(t.getHours(), 10);
		assertEquals(t.getMinutes(), 10);
	}

	@Test
	public void testTooManyMinutes() {
		try
		{
			MinTime t = new MinTime(10, 60);
		}
		catch(RuntimeException e)
		{
			//This should happen
		}
	}

	@Test
	public void testTooManyHours() {
		try
		{
			MinTime t = new MinTime(25, 10);
		}
		catch(RuntimeException e)
		{
			//This should happen
		}
	}

	@Test
	public void testTooManyMinutesHours() {
		try
		{
			MinTime t = new MinTime(24, 01);
		}
		catch(RuntimeException e)
		{
			//This should happen
		}
	}

	@Test
	public void testAddTime() {
		MinTime t = new MinTime(1, 30);
		t = t.add(new MinTime(0, 30));
		assertEquals(2, t.getHours());
		assertEquals(0, t.getMinutes());
	}

	@Test
	public void testTimeToMinutes() {
		MinTime t = new MinTime(3, 30);
		assertEquals(210, t.getAsMinutes());
	}
	
	@Test
	public void testTimeFromSeconds()
	{
		MinTime t = new MinTime(29);
		assertEquals(new MinTime(0,29), t);

		t = new MinTime(59);
		assertEquals(new MinTime(0,59), t);

		t = new MinTime(61);
		assertEquals(new MinTime(1,1), t);

		t = new MinTime(361);
		assertEquals(new MinTime(6,1), t);
	}
	
	@Test
	public void testMultTime()
	{
		MinTime t = new MinTime(1, 0);
		t = t.multBy(0.5f);
		assertEquals(t, new MinTime(0, 30));

		t = new MinTime(1, 0);
		t = t.multBy(2.0f);
		assertEquals(t, new MinTime(2, 0));
	}
}
